<template>
	<n-page>
		<view slot="navbar"></view>
		<view slot="header" style="height: 100%;">
			<z-paging ref="paging" @query="getData" :list.sync="dataList">
				<view slot="loading">
					<ns-loading></ns-loading>
				</view>
				<view class="bg-gray-1">
					<view class="padding-x-md border-bottom-xs border-dotted border-gray-5" style="border-top-width:0;border-left-width:0;border-right-width:0" v-for="(item, index) in dataList" :key="index">
						<view class="flex-row items-center padding-y-xs">
							<view class="margin-right-md">
								<n-icon v-if="item.account_data>0" name="pulldown" color="$red-6" size="70"></n-icon>
								<n-icon v-else name="pullup" color="$green-6" size="70"></n-icon>
							</view>
							<view class="flex-column flex-1">
								<view class="flex-row justify-between">
									<view class="text-md text-bold">{{ item.type_name }}</view>
									<view class="text-md color-red-6" v-if="item.account_data > 0">
										+{{ parseFloat(item.account_data) }}
									</view>
									<view class="text-lg color-gray-8" v-else>{{ parseFloat(item.account_data) }}</view>
								</view>
								<view class="text-xs color-gray-7">
									<text>{{ item.remark }}</text>
								</view>
								<view class="text-xs color-gray-7">
									<text>{{ $util.timeStampTurnTime(item.create_time) }}</text>
								</view>
							</view>
						</view>
					</view>
				</view>	
			</z-paging>

			<loading-cover ref="loadingCover"></loading-cover>
		</view>
	</n-page>
</template>

<script>
	export default {
		data() {
			return {
				dataList: [],
				statusList: [{
						name: '全部',
						id: '0'
					},
					{
						name: '收入',
						id: '1'
					},
					{
						name: '支出',
						id: '2'
					}
				],
				scrollInto: '',
				orderStatus: '0',
			};
		},
		onLoad(option) {
			if (option.status) this.orderStatus = option.status;
		},
		onShow() {
			// 刷新多语言
			this.$langConfig.refresh();
			if (!uni.getStorageSync('token')) {
				this.$refs.login.open('/otherpages/member/balance/balance');
			}
		},
		computed: {
			themeStyle() {
				return 'theme-' + this.$store.state.index.themeStyle
			}
		},
		methods: {
			ontabtap(e) {
				let index = e.currentTarget.dataset.current;
				this.orderStatus = this.statusList[index].id;
				this.$refs.paging.reload()
			},
			getData(pageNo, pageSize) {
				this.$api.sendRequest({
					url: '/api/memberaccount/page',
					data: {
						page_size: pageSize,
						page: pageNo,
						account_type: 'balance,locked_balance'
					},
					success: res => {
						if(res.code==-1&&res.error_code=='TOKEN_ERROR'){
							this.$util.showToast({'title':'登录失败'});
							let pageRouter=getCurrentPages();
							let data=pageRouter[pageRouter.length-1].options;
							let back=pageRouter[pageRouter.length-1].route;
							data.back=back;
							setTimeout(()=>{
								this.$util.redirectTo('/pages/login/login/login', data);
							},1500)
							return;
						}
						let newArr = [];
						let msg = res.message;
						if (res.code == 0 && res.data) {
							newArr = res.data.list;
						} else {
							this.$util.showToast({
								icon: 'none',
								title: msg
							});
						}
						this.$refs.paging.complete(newArr);
						if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
					},
					fail: res => {
						this.$refs.paging.complete(false);
						if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
					}
				});
			},
		}
	};
</script>

<style lang="scss">

</style>
